package com.mapper;

import com.pojo.SClass;
import com.pojo.Sdept;
import com.pojo.Student;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface StudentMapper {

    @Select("select * from student")
    List<Student> getList();

    @Select("select count(*) from student")
    Integer countStudents();

    @Select("select name from sdept where id = #{sdept_id}")
    String getSdeptName(Integer sdept_id);

    @Select("select name from s_class where id = #{class_id}")
    String getClassName(Integer class_id);

    @Select("select * from s_class where id = #{class_id}")
    SClass getClass(Integer class_id);

    @Select("select * from sdept")
    List<Sdept> getSdepts();

    @Select("select * from sdept where id = #{id}")
    Sdept getSdeptById(Integer id);

    @Select("select * from sdept where name = #{name}")
    Sdept getSdeptByName(String name);

    @Insert("insert into sdept(name) value(#{name})")
    void addSdept(String name);

    @Update("update sdept set name = #{name} where id = #{id}")
    void editSdept(Integer id,String name);

    @Delete("delete from sdept where id = #{id}")
    void delSdept(Integer id);

    @Select("select * from s_class where sdept_id = #{sdept_id}")
    List<SClass> getClassBySdept(Integer sdept_id);

    @Select("select * from s_class where sdept_id = #{sdept_id} and name = #{name}")
    SClass getClassBySdeptIdAndClassName(Integer sdept_id,String name);

    @Insert("insert into s_class(sdept_id,name) value(#{sdept_id},#{name})")
    void addClass(Integer sdept_id,String name);

    @Select("select * from s_class where id = #{id}")
    SClass getClassById(Integer id);

    @Update("update s_class set name = #{name} where id = #{id}")
    void editClass(Integer id,String name);

    @Delete("delete from s_class where id = #{id}")
    void delClass(Integer id);

    @Select("select * from student where open_id = #{open_id}")
    Student getInfo(String open_id);

    @Select("select * from student where account = #{account}")
    Student getByAccount(String account);

    @Select("select * from student where stunum = #{stunum}")
    Student getByStunum(String stunum);

    @Insert("insert into student(open_id,gender,nickname,avatar,account,password,stunum,class_id) value(#{open_id},#{gender},#{nickname},#{avatar},#{account},#{password},#{stunum},#{class_id})")
    void register(String open_id,Integer gender,String nickname,String avatar,String account,String password,String stunum,Integer class_id);


    @Update("update student set nickname = #{nickname} where open_id = #{open_id}")
    void editNickname(String open_id,String nickname);

}
